package cn.uce.cc.srv.biz.impl;

import cn.uce.base.PubApiObjectConstants;
import cn.uce.base.ccos.*;
import cn.uce.base.vo.ReceiptmoneyVo;
import cn.uce.base.vo.RepeatWorkBillVo;
import cn.uce.cc.api.service.biz.*;
import cn.uce.cc.srv.client.CcosInterfaceClient;
import cn.uce.cc.srv.client.JsonHttpClient;
import cn.uce.cc.srv.utils.HttpClientPubApiUtils;
import cn.uce.cc.srv.utils.ScreenBusiConditionUtils;
import cn.uce.cc.srv.utils.ScreenBusiWBPubApiConVer;
import cn.uce.common.omg.cache.FspDictDateCache;
import cn.uce.common.utils.DateUtil;
import cn.uce.utils.StringUtil;
import cn.uce.web.common.util.WebUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.*;

@Service("ccosWaybillBiz")
public class CcosWaybillBiz implements ICcosWaybillBiz {

    private Logger log = LoggerFactory.getLogger(CcosWaybillBiz.class);

    @Value("${spring.serviceName.queryRelatedNamesByuserCode}")
    private String queryRelatedNamesByuserCode;

    @Resource
    CcosInterfaceClient ccosInterfaceClient;

    @Value("${spring.serviceName.repeatWorkBill}")
    private String repeatWorkBill;


    @Value("${spring.serviceName.queryWaybillByNo}")
    private String queryWaybillByNo;

    @Resource
    private FspDictDateCache fspDictDateCache;

    @Resource
    private ICcosNetDistrictBiz ccosNetDistrictBiz;

    @Resource
    private ICcosRoutTrackBiz ccosRoutTrackBiz;

    @Resource
    private ICcosUserBiz ccosUserBiz;

    @Resource
    private ICcosOrgBiz ccosOrgBiz;

    @Override
    public String getWayBillProblem(String wayNum) {
        String wayBillProblem = "";
        Map map = new HashMap();
        map.put("wayBillNo", wayNum);
        try {
            log.info("api网关测试请求运单号"+wayNum);
            String msg_temp = HttpClientPubApiUtils.buildUpStructure(PubApiObjectConstants.WAYBILL_ABN_QUERY_BY_WAYBILL_NO,
                    map);
            log.info("api网关测试请求"+msg_temp);
            wayBillProblem = ccosInterfaceClient.getWayBillProblem(msg_temp);
            log.info("api网关测试响应"+wayBillProblem);
        }catch (Exception e){
            log.error("问题件查询接口失败",e);
        }
        return wayBillProblem;
    }

    @Override
    public String getWayBillProblems(String wayNum) {
        String wayBillProblem = "";
        Map map = new HashMap();
        map.put("wayBillNo", wayNum);
        try {
            String msg_temp = HttpClientPubApiUtils.buildUpStructure(PubApiObjectConstants.WAYBILL_ABN_QUERY_BY_WAYBILL_NO,
                    map);
            log.info("api网关测试请求"+msg_temp);
            wayBillProblem = ccosInterfaceClient.getWayBillProblems(msg_temp);
            log.info("api网关测试响应"+wayBillProblem);
        }catch (Exception e){
            log.error("问题件查询接口失败",e);
        }
        return wayBillProblem;
    }

    @Override
    public String getWayBillProblemDetail(String problemNum) {
        String wayBillProblemDetail = "";
        Map map = new HashMap();
        map.put("abnormalCode", problemNum);
        try {
            String msg_temp = HttpClientPubApiUtils
                    .buildUpStructure(PubApiObjectConstants.WAYBILL_ABN_QUERY_BY_ABNORMAL_CODE, map);
            log.info("api网关测试请求"+msg_temp);
            wayBillProblemDetail = ccosInterfaceClient.getWayBillProblemDetail(msg_temp);
            log.info("api网关测试响应"+wayBillProblemDetail);
        }catch (Exception e){
            log.error("问题件详情查询失败",e);
        }
        return wayBillProblemDetail;
    }

    @Override
    public String getWayBillProblemDetails(String problemNum) {
        String wayBillProblemDetail = "";
        Map map = new HashMap();
        map.put("abnormalCode", problemNum);
        try {
            String msg_temp = HttpClientPubApiUtils
                    .buildUpStructure(PubApiObjectConstants.WAYBILL_ABN_QUERY_BY_ABNORMAL_CODE, map);
            log.info("api网关测试请求"+msg_temp);
            wayBillProblemDetail = ccosInterfaceClient.getWayBillProblemDetails(msg_temp);
            log.info("api网关测试响应"+wayBillProblemDetail);
        }catch (Exception e){
            log.error("问题件详情查询失败",e);
        }
        return wayBillProblemDetail;
    }

    @Override
    public Map<String, Object> wayBillInfo(String wayNum) {
        Map<String, Object> map_wbinfo = new HashMap<String, Object>();
        String wayBillInfo = getWayBillInfoByWBNo(wayNum);
        map_wbinfo = converterQueryWB(wayBillInfo);
        if (map_wbinfo.isEmpty()) {
            return map_wbinfo;
        }
        // sign
        combineWBSignInfo(map_wbinfo, wayNum);
        // track 增值服务信息
        combineWBVaInfo(map_wbinfo, wayNum);
        LinkedList<RoutTrackVo> trackList = ccosRoutTrackBiz.getRoutingLocusInfoByWBNo(wayNum);
        if (trackList.size() > 0) {
            map_wbinfo.put("routingLocusInfo", trackList);
        }
        //对网点信息做转换
        combineWBForNetPointInfo(map_wbinfo);
        return map_wbinfo;
    }


     /**
       * 对网点做转换
       * @Author liupan
       * @Description
       * @Date  2020-07-01 14:07
       */
    private void combineWBForNetPointInfo(Map map) {
        if (!map.isEmpty()) {
            WayBillInfoVo wayBillInfoVo = (WayBillInfoVo) map.get("wayBillInfoVo");
            String str_api_start_point = ccosOrgBiz.getNetWorkInFo(wayBillInfoVo.getStartPointCode());
            Map map_api_start_point = ScreenBusiWBPubApiConVer.converterQueryNetWork(str_api_start_point);
            DepartmentVo departmentVo_start = (DepartmentVo) map_api_start_point.get("departmentVo");
            String str_api_end_point = ccosOrgBiz.getNetWorkInFo(wayBillInfoVo.getEndPointCode());
            Map map_api_end_point = ScreenBusiWBPubApiConVer.converterQueryNetWork(str_api_end_point);
            DepartmentVo departmentVo_end = (DepartmentVo) map_api_end_point.get("departmentVo");
            wayBillInfoVo.setStartPointPhone(departmentVo_start.getContactPhone());
            wayBillInfoVo.setEndPointPhone(departmentVo_end.getContactPhone());
            map.put("wayBillInfoVo", wayBillInfoVo);
        }
    }




    /**
     * 增值服务信息
     * @param map_wbinfo
     * @param wayNum
     */
    private void combineWBVaInfo(Map map_wbinfo, String wayNum)   {
        if (!map_wbinfo.isEmpty()) {
            VaInfoVo vaInfoVo = (VaInfoVo) map_wbinfo.get("vaInfoVo");
            String trans = getVaInfoVoByWBNo(wayNum);
            if (ScreenBusiConditionUtils.isEmptyForApi(trans, "data")) {
                JSONObject jSONObject_trans = JSONObject.parseObject(trans);
                String str_api_temp = jSONObject_trans.getString("data");
                List lst = JSONObject.parseArray(str_api_temp);
                if(null == lst){
                    return;
                }
                if (lst.size() > 0) {
                    for (Object obj : lst) {
                        JSONObject jSONObject = (JSONObject) obj;
                        if (StringUtil.isNotBlank(jSONObject.getString("paymentTm")))
                            vaInfoVo.setTransTime((DateUtil.getUTCTime(jSONObject.getString("paymentTm"))));
                        if (StringUtil.isNotBlank(jSONObject.getString("paymentStatus")))
                            vaInfoVo.setTransStatus(jSONObject.getString("paymentStatus"));
                        if (StringUtil.isNotBlank(jSONObject.getString("operStatus"))) {
                            vaInfoVo.setOperatStateName(fspDictDateCache.getTypeNmaeForTypeCode("va_operatstate",  jSONObject.getString("operStatus")));
                        }
                        if (StringUtil.isNotBlank(jSONObject.getString("yqResult"))) {
                            vaInfoVo.setTransResult(  fspDictDateCache.getTypeNmaeForTypeCode("TransResult", jSONObject.getString("yqResult")));
                        }
                        if (StringUtil.isNotBlank(jSONObject.getString("yqMsg")))
                            vaInfoVo.setFailReason(jSONObject.getString("yqMsg"));
                        if (StringUtil.isNotBlank(jSONObject.getString("receiveAccountName")))
                            vaInfoVo.setPayee(jSONObject.getString("receiveAccountName"));
                    }
                }
            }
            map_wbinfo.put("vaInfoVo", vaInfoVo);
        }
    }

    /**
     * 查询物流轨迹
     * @param wayBillNo
     * @return
     */
    public String getVaInfoVoByWBNo(String wayBillNo) {
        String transfer = "";
        // String url_param = "?waybillNo=" + wayBillNo;
        try {
            // transfer =
            // HttpClientPubApiUtils.sendMessageToPubApi_get(PubApiURLConstants.WAYBILL_TRANSFER_QUERY_BY_WAYBILL_NO
            // + url_param);
//            transfer = HttpclientTools.doGet(pubApiURLConstants.getWaybillTransferQueryByWaybillNo(), paramMap, null);
            log.info("api网关测试请求"+wayBillNo);
            transfer = ccosInterfaceClient.getVaInfoVoByWBNo(wayBillNo);
            log.info("api网关测试响应"+transfer);
        } catch (Exception e) {
            log.error("getVaInfoVoByWBNo：" + e);
        }
        return transfer;
    }

    @Override
    public String getArbitrationInfoByWBNo(String wayNum) {
        String arbitration = "";
        Map map = new HashMap();
        map.put("wayBillNo", wayNum);
        String msg_temp = HttpClientPubApiUtils.buildUpStructure(PubApiObjectConstants.WAYBILL_ARB_QUERY_BY_WAYBILL_NO,
                map);
        try {
            log.info("api网关测试请求"+msg_temp);
            arbitration = ccosInterfaceClient.getArbitrationInfoByWBNo(msg_temp);
            log.info("api网关测试响应"+arbitration);
        } catch (Exception e) {
            log.error("银河查询仲裁出现异常：" +e);
        }
        return arbitration;
    }

    @Override
    public String getComplaint(String complaintNum) {
        String complaint = "";
        Map map = new HashMap();
        map.put("arbitrationNo", complaintNum);
        String msg_temp = HttpClientPubApiUtils
                .buildUpStructure(PubApiObjectConstants.WAYBILL_ARB_QUERY_BY_COMPLAINT_NUM, map);
        try {
            log.info("api网关测试请求"+msg_temp);
            complaint = ccosInterfaceClient.getComplaintByCONo(msg_temp);
            log.info("api网关测试响应"+complaint);
        } catch (Exception e) {
            log.error("银河查询仲裁出现异常：" +e);
        }
        return complaint;
    }



    @Override
    public String repeatWorkBill(RepeatWorkBillVo repeatWorkBillVo) throws Exception{
        String empCode = WebUtil.getCurrentUser().getEmpCode();
        Map<String, Object> userInfo = ccosUserBiz.getUserInfo(empCode);
        /** 放入工单所需字段 */
        repeatWorkBillVo.setUserName(WebUtil.getCurrentUser().getEmpName());
        repeatWorkBillVo.setCompCode((String) userInfo.get("compCode"));
        repeatWorkBillVo.setCompName((String) userInfo.get("compLongName"));
        repeatWorkBillVo.setDeptCode((String) userInfo.get("siteCode"));
        repeatWorkBillVo.setDeptName((String) userInfo.get("siteName"));
        repeatWorkBillVo.setUserCode((String) userInfo.get("userCode"));
        repeatWorkBillVo.setDeptType("0");
        Map<String, Object> params = new HashMap<>();
        params.put("serviceName", repeatWorkBill);
        params.put("parameters", new Object[]{repeatWorkBillVo});
        String result = "msg";
        String msgTrue = "true";
        String success = "success";
        String returnMessage = null;
            String json = JsonHttpClient.postJsonForOpenPlatBridge(JSON.toJSONString(params));
            log.warn("api网关测试请求"+json);
            returnMessage = ccosInterfaceClient.queryOpenPlatFronBridge(json);
            log.warn("api网关测试响应"+returnMessage);
            if(null == returnMessage){
                return null;
            }
            JSONObject resultMessage = JSONObject.parseObject(returnMessage);
            if(msgTrue.equals(resultMessage.getString(success))){
                return "重复投诉成功";
            }
        return null;
    }



     /**
       * 桥接方法后getResult
       * @Author liupan
       * @Description
       * @Date  2020-07-06 10:47
       */
    @Override
    public String queryOpenPlatFronBridge(Map<String, Object> params) {
        String result = "result";
        String msgTrue = "true";
        String success = "success";
        String returnMessage = null;
        try {
            String json = JsonHttpClient.postJsonForOpenPlatBridge(JSON.toJSONString(params));
            log.warn("api网关测试请求"+json);
            returnMessage = ccosInterfaceClient.queryOpenPlatFronBridge(json);
            log.warn("api网关测试响应"+returnMessage);
            if(null == returnMessage){
                return null;
            }
            JSONObject resultMessage = JSONObject.parseObject(returnMessage);
            if(msgTrue.equals(resultMessage.getString(success))){
                return resultMessage.getString(result);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

     /**
       * 查询运单详情
       * @Author liupan
       * @Description
       * @Date  2020-07-14 10:17
      * @return
       */
    @Override
    public Map<String, Object> getWayBillInfoDetail(String wayNum) {
        if (StringUtil.isBlank(wayNum)) {
            return null;
        } else {
            wayNum = wayNum.trim();
        }
        Map<String, Object> params = new HashMap<>();
        params.put("serviceName", queryWaybillByNo);
        params.put("parameters", new Object[]{wayNum});
        String result = queryOpenPlatFronBridge(params);
        if (StringUtil.isNotBlank(result)) {
            Map<String, Object> resultMap = JSON.parseObject(result, Map.class);
            return resultMap;
        }
        return null;
    }

     /**
       * 根据运单号查询代收货款
       * @Author liupan
       * @Description
       * @Date  2020-07-20 16:54
       */
    @Override
    public VaInfoVo getVaInfoVoByBillCode(String billCode) {
        VaInfoVo vaInfoVo = new VaInfoVo();
        String trans = getVaInfoVoByWBNo(billCode);
        if (ScreenBusiConditionUtils.isEmptyForApi(trans, "data")) {
            JSONObject jSONObject_trans = JSONObject.parseObject(trans);
            String str_api_temp = jSONObject_trans.getString("data");
            List lst = JSONObject.parseArray(str_api_temp);
            if(null == lst){
                return null;
            }
            if (lst.size() > 0) {
                for (Object obj : lst) {
                    JSONObject jSONObject = (JSONObject) obj;
                    if (StringUtil.isNotBlank(jSONObject.getString("paymentTm")))
                        vaInfoVo.setTransTime((DateUtil.getUTCTime(jSONObject.getString("paymentTm"))));
                    if (StringUtil.isNotBlank(jSONObject.getString("paymentStatus")))
                        vaInfoVo.setTransStatus(jSONObject.getString("paymentStatus"));
                    if (StringUtil.isNotBlank(jSONObject.getString("operStatus"))) {
                        vaInfoVo.setOperatStateName(fspDictDateCache.getTypeNmaeForTypeCode("va_operatstate",  jSONObject.getString("operStatus")));
                    }
                    if (StringUtil.isNotBlank(jSONObject.getString("yqResult"))) {
                        vaInfoVo.setTransResult(  fspDictDateCache.getTypeNmaeForTypeCode("TransResult", jSONObject.getString("yqResult")));
                    }
                    if (StringUtil.isNotBlank(jSONObject.getString("yqMsg")))
                        vaInfoVo.setFailReason(jSONObject.getString("yqMsg"));
                    if (StringUtil.isNotBlank(jSONObject.getString("receiveAccountName")))
                        vaInfoVo.setPayee(jSONObject.getString("receiveAccountName"));
                    if (StringUtil.isNotBlank(jSONObject.getString("column5")))
                        vaInfoVo.setTransMoneyTime(jSONObject.getString("column5"));
                }
            }
            return vaInfoVo;
        }
    return null;
    }

    @Override
    public List<ReceiptmoneyVo> getReceiptMoney(String waybillNo) {
        String goodsPayment = "";
        try {
            log.info("api网关测试请求"+JSONObject.toJSONString(waybillNo));
            goodsPayment = ccosInterfaceClient.getReceiptMoney(waybillNo);
            log.info("api网关测试响应"+goodsPayment);
        }catch (Exception e){
            log.error("查询GoodsPayment出现异常",e);
        }
        return getReceiptMoneyTran(goodsPayment);
    }

    public String getWayBillChangeInfo(String wayBillNum) {
        String wayBillChangeInfo = "";
        Map<String, Object> map = new HashMap();
        map.put("waybillNoArray", wayBillNum);
        String jsonObject = HttpClientPubApiUtils
                .buildUpStructure(PubApiObjectConstants.WAYBILL_CHANGE_QUERY_BY_WAYBILL_NO, map);
        try {
            // wayBillChangeInfo =
            // HttpClientPubApiUtils.sendMessageToPubApi(PubApiURLConstants.WAYBILL_CHANGE_QUERY_BY_WAYBILL_NO,
            // jsonObject);
            //wayBillChangeInfo = HttpclientTools.doPostJson(pubApiURLConstants.getWaybillChangeQueryByWaybillNo(),
                   // jsonObject, null);
            log.info("api网关测试请求"+wayBillNum);
            wayBillChangeInfo = ccosInterfaceClient.getWayBillChangeInfo(jsonObject);
            log.info("api网关测试响应"+wayBillChangeInfo);
        } catch (Exception e) {
            log.error("getWayBillChangeInfo出现异常：" + e);
        }
        return wayBillChangeInfo;
    }

    public List<ReceiptmoneyVo> getReceiptMoneyTran(String str_api)  {
        List<ReceiptmoneyVo> lst_ReceiptmoneyVo = new ArrayList();
        if (!ScreenBusiConditionUtils.isEmptyForApi(str_api, "data")) {
            return lst_ReceiptmoneyVo;
        }
        ReceiptmoneyVo receiptmoneyVo = null;
        JSONObject jSONObject = JSONObject.parseObject(str_api);
        String str_temp = jSONObject.getString("data");
        List<Object> lst = jSONObject.parseArray(str_temp);
        for (Object obj : lst) {
            receiptmoneyVo = new ReceiptmoneyVo();
            JSONObject jSONObject_obj = (JSONObject) obj;
            if (StringUtils.isNotBlank(jSONObject_obj.getString("operType"))) {
                Object object = fspDictDateCache.getTypeNmaeForTypeCode("receiptmoney_operateType",jSONObject_obj.getString("operType"));
                        //ccosNetDistrictBiz.getValueBykey(Constant.STATIC_NAME, "waybill_receiptmoney",
                      //  "receiptmoney_operateType", jSONObject_obj.getString("operType"));

                // jedisTools.getString(Constant.STATIC_NAME
                // + "waybill_receiptmoneyreceiptmoney_operateType" +
                // jSONObject_obj.getString("operType"));
                receiptmoneyVo.setOperateTypeName(object == null ? "" : object.toString());
            }
            if (StringUtils.isNotBlank(jSONObject_obj.getString("operAfter"))) {
                receiptmoneyVo.setOperateContent(jSONObject_obj.getString("operAfter"));
            }
            if (StringUtils.isNotBlank(jSONObject_obj.getString("operTm"))) {
                receiptmoneyVo
                        .setOperateTime(DateUtil.getUTCTime(jSONObject_obj.getString("operTm"), "yyyy-MM-dd HH:mm"));
            }
            if (StringUtils.isNotBlank(jSONObject_obj.getString("creater"))) {
                receiptmoneyVo.setOperater(jSONObject_obj.getString("creater"));
            }
            if (StringUtils.isNotBlank(jSONObject_obj.getString("operDeptCode"))) {
                receiptmoneyVo.setOperateDep(jSONObject_obj.getString("operDeptCode"));
            }
            if (StringUtils.isNotBlank(jSONObject_obj.getString("compCode"))) {
                receiptmoneyVo.setOperateCom(jSONObject_obj.getString("compCode"));
            }
            lst_ReceiptmoneyVo.add(receiptmoneyVo);
        }
        return lst_ReceiptmoneyVo;
    }


    @Override
    public String getWayBillInfoByWBNo(String wayBillNo) {
        String wayBillInfo = "";
        Map map = new HashMap();
        map.put("wayBillNo", wayBillNo);
        String jsonObject = HttpClientPubApiUtils.buildUpStructure(PubApiObjectConstants.WAYBILL_QUERY_BY_WAYBILL_NO,
                map);
        try {
            // wayBillInfo =
            // HttpClientPubApiUtils.sendMessageToPubApi(PubApiURLConstants.WAYBILL_QUERY_BY_WAYBILL_NO,
            // jsonObject);
//             wayBillInfo = HttpclientTools.doPostJson(pubApiURLConstants.getWaybillQueryByWaybillNo(), jsonObject, null);
            log.info("api网关测试请求"+jsonObject);
            wayBillInfo = ccosInterfaceClient.waybillQueryByWaybillNo(jsonObject);
            log.info("api网关测试响应"+wayBillInfo);
        } catch (Exception e) {
            log.error("银河查询运单信息出现异常：" +e);
        }
        return wayBillInfo;
    }


    /**
     * @MethodName combineWBSignInfo
     * @param map_wbinfo
     * @param wayNum
     */
    private void combineWBSignInfo(Map map_wbinfo, String wayNum) {
        if (!map_wbinfo.isEmpty()) {
            CusInfoVo cusInfoVo = (CusInfoVo) map_wbinfo.get("cusInfoVo");
            String sign = getDeliverySignVoByWBNo(wayNum);
            // Map map_sign = ScreenBusiWBPubApiConVer.converterQuerySign(sign);
            if (ScreenBusiConditionUtils.isEmptyForApi(sign, "data")) {
                JSONObject jSONObject = JSONObject.parseObject(sign);
                String str_api_temp = jSONObject.getString("data");
                DeliverySignVo deliverySignVo = JSONObject.parseObject(str_api_temp, DeliverySignVo.class);
                if (null != deliverySignVo) {
                    // DeliverySignVo deliverySignVo = (DeliverySignVo)
                    // map_sign.get("deliverySignVo");
                    if (StringUtil.isNotBlank(deliverySignVo.getSignerName()))
                        cusInfoVo.setSignerName(deliverySignVo.getSignerName());
                    if (null != deliverySignVo.getSignTime())
                        cusInfoVo.setSigTime(DateUtil.dateToString(deliverySignVo.getSignTime(), null));
                    if (null != deliverySignVo.getSignStatus()) {
//                        Object object = dictionaryServiceImpl.getValueBykey(Constant.STATIC_NAME, "customer_base_info",
//                                "customer_sigstatus", deliverySignVo.getSignStatus().toString());
//                        fspDictDateCache.getTypeNmaeForTypeCode("customer_sigstatus",  deliverySignVo.getSignStatus().toString())
//                        // jedisTools.getString(Constant.STATIC_NAME +
//                        // "customer_base_infocustomer_sigstatus"
//                        // + deliverySignVo.getSignStatus());
                        cusInfoVo.setSigstatusName(  fspDictDateCache.getTypeNmaeForTypeCode("customer_sigstatus",  deliverySignVo.getSignStatus().toString()));
                    }
                    if (null != deliverySignVo.getSignType()) {
//                        Object object = dictionaryServiceImpl.getValueBykey(Constant.STATIC_NAME, "customer_base_info",
//                                "customer_sigType", deliverySignVo.getSignType().toString());
//                        // jedisTools.getString(Constant.STATIC_NAME +
//                        // "customer_base_infocustomer_sigType"
//                        // + deliverySignVo.getSignType());
//                        fspDictDateCache.getTypeNmaeForTypeCode("customer_sigType",  deliverySignVo.getSignType().toString())
                        cusInfoVo.setSigTypeName(fspDictDateCache.getTypeNmaeForTypeCode("customer_sigType",  deliverySignVo.getSignType().toString()));
                    }
                }
                map_wbinfo.put("cusInfoVo", cusInfoVo);
            }
        }
    }


     /**
       * 获取快运运单签收信息
       * @Author liupan
       * @Description
       * @Date  2020-07-01 13:59
       */
    public String getDeliverySignVoByWBNo(String wayBillNo) {
        String deliverySignVo = "";
        Map<String, Object> map = new HashMap();
        map.put("wayBillNo", wayBillNo);
        String msg_temp = HttpClientPubApiUtils.buildUpStructure(PubApiObjectConstants.WAYBILL_SIGN_QUERY_BY_WAYBILL_NO,
                map);
        try {
//            deliverySignVo = HttpclientTools.doPostJson(pubApiURLConstants.getWaybillSignQueryByWaybillNo(), msg_temp,
//                    null);
            log.info("api网关测试请求"+msg_temp);
            deliverySignVo = ccosInterfaceClient.waybillSignQueryByWaybillNo(msg_temp);
            log.info("api网关测试响应"+deliverySignVo);
        } catch (Exception e) {
            log.error("银河getDeliverySignVoByWBNo出现异常：" + e);
        }
        return deliverySignVo;
    }

    public Map<String, Object> converterQueryWB(String str_api)  {
        Map<String, Object> collectionObject = new HashMap<String, Object>();
        JSONObject jSONObject = JSONObject.parseObject(str_api);
        if (null != jSONObject) {
            String str_api_temp = jSONObject.getString("data");
            if (!ScreenBusiConditionUtils.isEmptyForApi(str_api, "data"))
                return collectionObject;
            JSONObject jSONObject_temp = JSONObject.parseObject(str_api_temp);
            String str_api_conver_temp = jSONObject_temp.getString("waybillExtendList");
            if (!ScreenBusiConditionUtils.isEmptyForApi(str_api_temp, "waybillExtendList"))
                return collectionObject;
            List<Object> lst = JSONObject.parseArray(str_api_conver_temp);
            WayBillInfoVo wayBillInfoVo = new WayBillInfoVo();
            GoodsInfoVo goodsInfoVo = new GoodsInfoVo();
            SettleInfoVo settleInfoVo = new SettleInfoVo();
            VaInfoVo vaInfoVo = new VaInfoVo();
            CusInfoVo cusInfoVo = new CusInfoVo();
            for (Object obj : lst) {
                String str = obj.toString();
                WaybillExtendVo waybillExtendVo = JSONObject.parseObject(str, WaybillExtendVo.class);
                if(null!=waybillExtendVo.getCompCode()){
                    wayBillInfoVo.setCompCode(waybillExtendVo.getCompCode());
                }
                if(null!=waybillExtendVo.getToCompCode()){
                    wayBillInfoVo.setToCompCode(waybillExtendVo.getToCompCode());
                }
                if (null != waybillExtendVo.getDataSourceType()) {
                    wayBillInfoVo.setWaybillFlag(String.valueOf(waybillExtendVo.getWaybillFlag()));
                }
                if (null != waybillExtendVo.getRouteName()) {
                    wayBillInfoVo.setRouteName(String.valueOf(waybillExtendVo.getRouteName()));
                }
                if (null != waybillExtendVo.getWaybillNo()) {
                    wayBillInfoVo.setWayNum(String.valueOf(waybillExtendVo.getWaybillNo()));
                }
                if (StringUtil.isNotEmpty(waybillExtendVo.getGoodsNo())) {
                    wayBillInfoVo.setInvNum(waybillExtendVo.getGoodsNo());
                }
                if (StringUtil.isNotEmpty(waybillExtendVo.getProductType())) {
                    wayBillInfoVo.setProTypeName(fspDictDateCache.getTypeNmaeForTypeCode("waybill_protype", waybillExtendVo.getProductType()));
                }
                if (null != waybillExtendVo.getBusinessModel()) {
                    wayBillInfoVo.setBusiAttrName(fspDictDateCache.getTypeNmaeForTypeCode("waybill_runproper",  waybillExtendVo.getBusinessModel().toString()));
                }
                if (null != waybillExtendVo.getCreaterTime()) {
                    wayBillInfoVo.setCreaTime(DateUtil.dateToString(waybillExtendVo.getCreaterTime(), null));
                }
                if (StringUtil.isNotEmpty(waybillExtendVo.getCreater())) {
                    wayBillInfoVo.setWayCreator(waybillExtendVo.getCreater());
                }
                if (StringUtil.isNotEmpty(waybillExtendVo.getRelationWaybillNo())) {
                    wayBillInfoVo.setAsoNum(waybillExtendVo.getRelationWaybillNo());
                }
                if (null != waybillExtendVo.getBizType()) {
                    wayBillInfoVo.setBusTypeName(fspDictDateCache.getTypeNmaeForTypeCode("waybill_busttype",waybillExtendVo.getBizType().toString()));
                }
                if (null != waybillExtendVo.getServiceType()) {
                    wayBillInfoVo.setSerMethodName(fspDictDateCache.getTypeNmaeForTypeCode("waybill_server",waybillExtendVo.getServiceType().toString()));
                }
                if (null != waybillExtendVo.getWaybillType()) {
                    wayBillInfoVo.setWayTypeName(fspDictDateCache.getTypeNmaeForTypeCode("waybill_waytype",waybillExtendVo.getWaybillType().toString()));
                }
                if (null != waybillExtendVo.getDataSourceType()) {
                    wayBillInfoVo.setDataSourceName(fspDictDateCache.getTypeNmaeForTypeCode("waybill_datasource",waybillExtendVo.getDataSourceType().toString()));
                }
                if (null != waybillExtendVo.getManualFlag()) {
                    wayBillInfoVo.setManMarkName(waybillExtendVo.getManualFlag());
                }
                if (StringUtil.isNotEmpty(waybillExtendVo.getSourceZoneName())) {
                    wayBillInfoVo.setStartPoint(waybillExtendVo.getSourceZoneName());
                }
                if (StringUtil.isNotEmpty(waybillExtendVo.getDestZoneName())) {
                    wayBillInfoVo.setEndPoint(waybillExtendVo.getDestZoneName());
                }
                if (StringUtil.isNotEmpty(waybillExtendVo.getSourceZoneCode())) {
                    wayBillInfoVo.setStartPointCode(waybillExtendVo.getSourceZoneCode());
                }
                if (StringUtil.isNotEmpty(waybillExtendVo.getDestZoneCode())) {
                    wayBillInfoVo.setEndPointCode(waybillExtendVo.getDestZoneCode());
                }
                if (StringUtil.isNotEmpty(waybillExtendVo.getSender())) {
                    cusInfoVo.setSenderName(waybillExtendVo.getSender());
                }
                if (null != waybillExtendVo.getSendTime()) {
                    cusInfoVo.setSendTime(DateUtil.dateToString(waybillExtendVo.getSendTime(), null));
                }
                if (StringUtil.isNotEmpty(waybillExtendVo.getSendPhone())) {
                    cusInfoVo.setSenderPhone(waybillExtendVo.getSendPhone());
                }
                if (StringUtil.isNotEmpty(waybillExtendVo.getCardNo())) {
                    cusInfoVo.setMemCardNum(waybillExtendVo.getCardNo());
                }
                if (StringUtil.isNotEmpty(waybillExtendVo.getSenderAddress())) {
                    cusInfoVo.setSenderAdderss(waybillExtendVo.getSenderAddress());
                }
                if (StringUtil.isNotEmpty(waybillExtendVo.getConsignee())) {
                    cusInfoVo.setRecipName(waybillExtendVo.getConsignee());
                }
                if (StringUtil.isNotEmpty(waybillExtendVo.getConsigneePhone())) {
                    cusInfoVo.setRecipPhone(waybillExtendVo.getConsigneePhone());
                }
                if (StringUtil.isNotEmpty(waybillExtendVo.getConsigneeAddress())) {
                    cusInfoVo.setRecipAdress(waybillExtendVo.getConsigneeAddress());
                }
                if (StringUtil.isNotEmpty(waybillExtendVo.getDispatchSmallAreaCode())) {
                    cusInfoVo.setDeliveryAddress(waybillExtendVo.getDispatchSmallAreaCode());
                }
                if (StringUtil.isNotEmpty(waybillExtendVo.getSendAddressCode())) {
                    // cusInfoVo.setSendAddressCode(waybillExtendVo.getSendAddressCode());
                    if (!StringUtil.isNotBlank(ccosNetDistrictBiz.areaCodeToName(waybillExtendVo.getSendAddressCode()))) {
                        cusInfoVo.setSendAddress(ccosNetDistrictBiz.areaCodeToName(waybillExtendVo.getSendAddressCode()));
                    }
                }
                if (StringUtil.isNotEmpty(waybillExtendVo.getConsigneeAddressCode())) {
                    // cusInfoVo.setConsigneeAddressCode(waybillExtendVo.getConsigneeAddressCode());
                    if (!StringUtil.isNotBlank(
                            ccosNetDistrictBiz.areaCodeToName(waybillExtendVo.getConsigneeAddressCode()))) {

                        cusInfoVo.setConsigneeAddress(
                                ccosNetDistrictBiz.areaCodeToName(waybillExtendVo.getConsigneeAddressCode()));
                    }
                }
                if (StringUtil.isNotEmpty(waybillExtendVo.getForwardName())) {
                    cusInfoVo.setForwardAddress(waybillExtendVo.getForwardName());
                    cusInfoVo.setViaOutlet(waybillExtendVo.getForwardName());
                }
                if (null != waybillExtendVo.getForwardFee()) {
                    cusInfoVo.setForwardFee(String.valueOf(waybillExtendVo.getForwardFee()));
                }
                if (StringUtil.isNotEmpty(waybillExtendVo.getConsignName())) {
                    goodsInfoVo.setGoodsName(waybillExtendVo.getConsignName());
                }
                if (null != waybillExtendVo.getRealWeight()) {
                    goodsInfoVo.setGoodsWeight(String.valueOf(waybillExtendVo.getRealWeight()));
                }
                if (null != waybillExtendVo.getChargeableUnit()) {
                    goodsInfoVo.setGoodsBillUnit(String.valueOf(waybillExtendVo.getChargeableUnit()));
                }
                if (null != waybillExtendVo.getCouponAmount()) {
                    goodsInfoVo.setCouponPrice(String.valueOf(waybillExtendVo.getCouponAmount()));
                }
                if (null != waybillExtendVo.getQuantity()) {
                    goodsInfoVo.setGoodsAmount(String.valueOf(waybillExtendVo.getQuantity()));
                }
                if (null != waybillExtendVo.getVolume()) {
                    goodsInfoVo.setGoodsVolume(String.valueOf(waybillExtendVo.getVolume()));
                }
                if (null != waybillExtendVo.getChargeableWeight()) {
                    goodsInfoVo.setGoodsBillWeight(String.valueOf(waybillExtendVo.getChargeableWeight()));
                }
                if (StringUtil.isNotEmpty(waybillExtendVo.getCouponCode())) {
                    goodsInfoVo.setGoodsCoupon(waybillExtendVo.getCouponCode());
                }
                if (StringUtil.isNotEmpty(waybillExtendVo.getPackingSpecification())) {
                    goodsInfoVo.setGoodsPackage(waybillExtendVo.getPackingSpecification());
                }
                if (null != waybillExtendVo.getPackageFee()) {
                    goodsInfoVo.setGoodsPackFee(String.valueOf(waybillExtendVo.getPackageFee()));
                }
                if (null != waybillExtendVo.getMemo()) {
                    goodsInfoVo.setGoodsRemark(String.valueOf(waybillExtendVo.getMemo()));
                }
                if (null != waybillExtendVo.getSettlementType()) {
                    settleInfoVo.setBillTypeName(fspDictDateCache.getTypeNmaeForTypeCode("settle_type",waybillExtendVo.getSettlementType().toString()));
                }
                if (null != waybillExtendVo.getExpressFee()) {
                    settleInfoVo.setBillFare(String.valueOf(waybillExtendVo.getExpressFee()));
                }
                if (null != waybillExtendVo.getPaidPaymentAmount()) {
                    settleInfoVo.setBillTotalPay(String.valueOf(waybillExtendVo.getPaidPaymentAmount()));
                }
                if (null != waybillExtendVo.getPaymentAmount()) {
                    settleInfoVo.setBillPayAmount(String.valueOf(waybillExtendVo.getPaymentAmount()));
                }
                if (null != waybillExtendVo.getDonationPaymentAmount()) {
                    settleInfoVo.setBillSendPayAmount(String.valueOf(waybillExtendVo.getDonationPaymentAmount()));
                }
                if (null != waybillExtendVo.getTotalFreight()) {
                    settleInfoVo.setBillCost(String.valueOf(waybillExtendVo.getTotalFreight()));
                }
                if (null != waybillExtendVo.getPaymentType()) {
                    settleInfoVo.setBillPayTypeName(fspDictDateCache.getTypeNmaeForTypeCode("settle_type",waybillExtendVo.getPaymentType().toString()));
                }
                if (null != waybillExtendVo.getDonationFee()) {
                    settleInfoVo.setBillPayType(String.valueOf(waybillExtendVo.getDonationFee()));
                }
                if (null != waybillExtendVo.getReceiveAmount()) {
                    settleInfoVo.setBillPayType(String.valueOf(waybillExtendVo.getReceiveAmount()));
                }
                if (StringUtil.isNotEmpty(waybillExtendVo.getInsuranceGoodsType())) {

                    vaInfoVo.setInsureTypeName(fspDictDateCache.getTypeNmaeForTypeCode("va_insuretype",waybillExtendVo.getInsuranceGoodsType()));
                }
                if (null != waybillExtendVo.getInsuranceAgentFee()) {
                    vaInfoVo.setInsureSerFee(String.valueOf(waybillExtendVo.getInsuranceAgentFee()));
                }
                if (null != waybillExtendVo.getCollectionWaybillFee()) {
                    vaInfoVo.setProxyFree(String.valueOf(waybillExtendVo.getCollectionWaybillFee()));
                }
                if (null != waybillExtendVo.getInsuranceFee()) {
                    vaInfoVo.setAffValue(String.valueOf(waybillExtendVo.getInsuranceFee()));
                }
                if (null != waybillExtendVo.getGoodsChargeFee()) {
                    vaInfoVo.setProxyPay(String.valueOf(waybillExtendVo.getGoodsChargeFee()));
                }
                if (null != waybillExtendVo.getChargeAgentFee()) {
                    vaInfoVo.setProxySerFree(String.valueOf(waybillExtendVo.getChargeAgentFee()));
                }
                if (StringUtil.isNotEmpty(waybillExtendVo.getBankType())) {
                    vaInfoVo.setBankType(waybillExtendVo.getBankType());
                    vaInfoVo.setBankTypeName(fspDictDateCache.getTypeNmaeForTypeCode("va_banktype",waybillExtendVo.getBankType()));
                }
                if (StringUtil.isNotEmpty(waybillExtendVo.getBankNo())) {
                    vaInfoVo.setBankAccount(waybillExtendVo.getBankNo());
                }
                if (StringUtil.isNotEmpty(waybillExtendVo.getTimeEfficiency())) {
                    vaInfoVo.setPayRebateName(fspDictDateCache.getTypeNmaeForTypeCode("pay_rebate",waybillExtendVo.getTimeEfficiency()));
                }
                if (null != waybillExtendVo.getIsSingBack()) {
                    vaInfoVo.setIssign(waybillExtendVo.getIsSingBack());
                }
                if (StringUtil.isNotEmpty(waybillExtendVo.getSingBackZs())) {
                    vaInfoVo.setReturnSheets(waybillExtendVo.getSingBackZs());
                }
                if (null != waybillExtendVo.getServiceFee()) {
                    vaInfoVo.setServFee(String.valueOf(waybillExtendVo.getServiceFee()));
                }
                if (StringUtil.isNotEmpty(waybillExtendVo.getSingBackFs())) {
                    vaInfoVo.setReturnCopies(waybillExtendVo.getSingBackFs());
                }
                if (null != waybillExtendVo.getSignBackFee()) {
                    vaInfoVo.setReturnFee(String.valueOf(waybillExtendVo.getSignBackFee()));
                }
                if (null != waybillExtendVo.getInvoiceTaxesFee()) {
                    vaInfoVo.setInvoiceTax(String.valueOf(waybillExtendVo.getInvoiceTaxesFee()));
                }
                if (null != waybillExtendVo.getKickBackFee()) {
                    vaInfoVo.setRebate(String.valueOf(waybillExtendVo.getKickBackFee()));
                }
                if (null != waybillExtendVo.getNoticeFee()) {
                    vaInfoVo.setNoticeFee(String.valueOf(waybillExtendVo.getNoticeFee()));
                }
                if (null != waybillExtendVo.getDeliverFee()) {
                    vaInfoVo.setUpDeliveryFee(String.valueOf(waybillExtendVo.getDeliverFee()));
                }
                if (null != waybillExtendVo.getDoorFee()) {
                    vaInfoVo.setToDoorRecFee(String.valueOf(waybillExtendVo.getDoorFee()));
                }
                if (null != waybillExtendVo.getCapitalFee()) {
                    vaInfoVo.setCapitalFee(String.valueOf(waybillExtendVo.getCapitalFee()));
                }
                if (null != waybillExtendVo.getCarFee()) {
                    vaInfoVo.setForkliftFee(String.valueOf(waybillExtendVo.getCarFee()));
                }
                if (null != waybillExtendVo.getDownDispatchFee()) {
                    vaInfoVo.setDownDeliveryFee(String.valueOf(waybillExtendVo.getDownDispatchFee()));
                }
                if (null != waybillExtendVo.getLoadingFee()) {
                    vaInfoVo.setLoadFee(String.valueOf(waybillExtendVo.getLoadingFee()));
                }
                if (null != waybillExtendVo.getUpstairsFee()) {
                    vaInfoVo.setUpfloorFee(String.valueOf(waybillExtendVo.getUpstairsFee()));
                }
                if (null != waybillExtendVo.getDeboursWayFee()) {
                    vaInfoVo.setPadFee(String.valueOf(waybillExtendVo.getDeboursWayFee()));
                }
                if (null != waybillExtendVo.getVoucherFee()) {
                    vaInfoVo.setProbillFee(String.valueOf(waybillExtendVo.getVoucherFee()));
                }
                if (null != waybillExtendVo.getWarhouseManeFee()) {
                    vaInfoVo.setWarehouseFee(String.valueOf(waybillExtendVo.getWarhouseManeFee()));
                }
                if (null != waybillExtendVo.getSmsFee()) {
                    vaInfoVo.setMsgFee(String.valueOf(waybillExtendVo.getSmsFee()));
                }
                if (null != waybillExtendVo.getIntoWarehousingFee()) {
                    vaInfoVo.setDepotFee(String.valueOf(waybillExtendVo.getIntoWarehousingFee()));
                }
                if (null != waybillExtendVo.getTransferFee()) {
                    vaInfoVo.setTransFee(String.valueOf(waybillExtendVo.getTransferFee()));
                }
                if (null != waybillExtendVo.getOtherFee()) {
                    vaInfoVo.setOtherFee(String.valueOf(waybillExtendVo.getOtherFee()));
                }
                collectionObject.put("wayBillInfoVo", wayBillInfoVo);
                collectionObject.put("cusInfoVo", cusInfoVo);
                collectionObject.put("goodsInfoVo", goodsInfoVo);
                collectionObject.put("settleInfoVo", settleInfoVo);
                collectionObject.put("vaInfoVo", vaInfoVo);
            }
        }
        return collectionObject;
    }

}
